﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BankSimulation
{
    //账户类
    internal class Account
    {
        //----------字段----------
        private double money;//余额
        private string id;//账户id
        private string pwd;//账户密码
        private string accountType;//账户类型字符串

        //----------属性----------
        public double Money
        {
            get { return money; }
            set { money = value; }
        }
        public string Id
        {
            //id只能读不能改
            get { return id; }
        }
        public string Password
        {
            get { return pwd; }
            set { pwd = value; }
        }
        public string AccountType
        {
            get { return accountType; }
            set { accountType = value; }
        }

        //----------方法----------
        //构造函数，初始化账户
        public Account(string id, string pwd, double money)
        {
            this.money = money;
            this.id = id;
            this.pwd = pwd;
        }
        //存钱方法
        public bool SaveMoney(double money)
        {
            if(money <= 0)
            {
                MessageBox.Show("存钱失败，不可存入负数");
                return false;
            }
            else
            {
                MessageBox.Show($"存钱成功！本次存入{money}");
                this.money += money;
                return true;
            }
        }
        //取钱方法
        public virtual bool WithdrawMoney(double money)
        {
            if(this.money <= money)
            {
                MessageBox.Show("取钱失败，余额不足");
                return false;
            }
            else
            {
                MessageBox.Show($"取钱成功！本次取出{money}");
                this.money -= money;
                return true;
            }
        }
        //判断账号是否存在
        public bool IsExist(string id, string pwd)
        {
            if (id == this.id && pwd == this.pwd)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
